import java.util.PriorityQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 62536
 * Date: 2024-06-05
 * Time: 21:11
 */
public class Solution {
    public int halveArray(int[] nums) {

        PriorityQueue<Double> heap = new PriorityQueue<>((a,b) -> b.compareTo(a));

        double sum = 0.0;
        for (int num : nums) {
            heap.offer((double)num);
            sum += (double) num;
        }
        sum /= 2.0;

        int count = 0;
        while(sum > 0){
            double x = heap.poll() / 2.0;
            sum -= x;
            count++;
            heap.offer(x);
        }

        return count;
    }
}
